﻿using System;
using System.IO;

namespace FindJPG
{
    class Program
    {
        const string TypeofFile = ".jpg";
        static int number = 0; //统计照片的个数
        static void SearchJPG(DirectoryInfo info)
        {
            foreach ( var Subdirectory in info.GetDirectories())//遍历子目录
            {
                try
                {
                    SearchJPG(Subdirectory);//递归遍历每一级子目录
                }
                catch (Exception)
                {
                    continue;
                }
            }
            foreach ( FileInfo CJPG in info.GetFiles(@"*.jpg"))
            {
                Console.WriteLine(CJPG.FullName);
                number++;
            }
        }
        static void Main(string[] args)
        {
            DirectoryInfo info = new DirectoryInfo(@"C:\");
            SearchJPG(info);
            Console.WriteLine();
            Console.WriteLine("C盘一共有{0}张照片", number);
        }
    }
}
